home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / sprite / RCS / final.c,v < prev    next >
Encoding:
Text File  |  1991-09-12  |  42.4 KB  |  1,654 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     91.09.12.15.37.52;  author rab;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.11.01.22.26.58;  author rab;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @*** empty log message ***
  27. @
  28. text
  29. @/* Convert RTL to assembler code and output it, for GNU compiler.
  30.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  31.  
  32. This file is part of GNU CC.
  33.  
  34. GNU CC is free software; you can redistribute it and/or modify
  35. it under the terms of the GNU General Public License as published by
  36. the Free Software Foundation; either version 1, or (at your option)
  37. any later version.
  38.  
  39. GNU CC is distributed in the hope that it will be useful,
  40. but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  42. GNU General Public License for more details.
  43.  
  44. You should have received a copy of the GNU General Public License
  45. along with GNU CC; see the file COPYING.  If not, write to
  46. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  47.  
  48.  
  49. /* This is the final pass of the compiler.
  50.    It looks at the rtl code for a function and outputs assembler code.
  51.  
  52.    Call `final_start_function' to output the assembler code for function entry,
  53.    `final' to output assembler code for some RTL code,
  54.    `final_end_function' to output assembler code for function exit.
  55.    If a function is compiled in several pieces, each piece is
  56.    output separately with `final'.
  57.  
  58.    Some optimizations are also done at this level.
  59.    Move instructions that were made unnecessary by good register allocation
  60.    are detected and omitted from the output.  (Though most of these
  61.    are removed by the last jump pass.)
  62.  
  63.    Instructions to set the condition codes are omitted when it can be
  64.    seen that the condition codes already had the desired values.
  65.  
  66.    In some cases it is sufficient if the inherited condition codes
  67.    have related values, but this may require the following insn
  68.    (the one that tests the condition codes) to be modified.
  69.  
  70.    The code for the function prologue and epilogue are generated
  71.    directly as assembler code by the macros FUNCTION_PROLOGUE and
  72.    FUNCTION_EPILOGUE.  Those instructions never exist as rtl.  */
  73.  
  74. #include <stdio.h>
  75. #include "config.h"
  76. #include "rtl.h"
  77. #include "regs.h"
  78. #include "insn-config.h"
  79. #include "recog.h"
  80. #include "conditions.h"
  81. #include "gdbfiles.h"
  82. #include "flags.h"
  83. #include "real.h"
  84. #include "output.h"
  85.  
  86. /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */
  87. #ifdef DBX_DEBUGGING_INFO
  88. #ifdef USG
  89. #include "stab.h"  /* If doing DBX on sysV, use our own stab.h.  */
  90. #else
  91. #include <stab.h>  /* On BSD, use the system's stab.h.  */
  92. #endif /* not USG */
  93. #endif /* DBX_DEBUGGING_INFO */
  94.  
  95. /* .stabd code for line number.  */
  96. #ifndef N_SLINE
  97. #define    N_SLINE    0x44
  98. #endif
  99.  
  100. /* .stabs code for included file name.  */
  101. #ifndef N_SOL
  102. #define    N_SOL 0x84
  103. #endif
  104.  
  105. #define min(A,B) ((A) < (B) ? (A) : (B))
  106.  
  107. rtx peephole ();
  108. void output_asm_insn ();
  109. rtx alter_subreg ();
  110. static int alter_cond ();
  111. void output_asm_label ();
  112. static void output_operand ();
  113. void output_address ();
  114. void output_addr_const ();
  115. static void output_source_line ();
  116. rtx final_scan_insn ();
  117.  
  118. /* the sdb debugger needs the line given as an offset from the beginning
  119.    of the current function -wfs*/
  120.  
  121. extern int sdb_begin_function_line;
  122.  
  123. /* Line number of last NOTE.  */
  124. static int last_linenum;
  125.  
  126. /* Number of basic blocks seen so far;
  127.    used if profile_block_flag is set.  */
  128. static int count_basic_blocks;
  129.  
  130. /* Nonzero while outputting an `asm' with operands.
  131.    This means that inconsistencies are the user's fault, so don't abort.
  132.    The precise value is the insn being output, to pass to error_for_asm.  */
  133. static rtx this_is_asm_operands;
  134.  
  135. /* Number of operands of this insn, for an `asm' with operands.  */
  136. static int insn_noperands;
  137.  
  138. /* File in which assembler code is being written.  */
  139.  
  140. extern FILE *asm_out_file;
  141.  
  142. /* Compare optimization flag. */
  143.  
  144. static rtx last_ignored_compare = 0;
  145.  
  146. /* Flag indicating this insn is the start of a new basic block. */
  147.  
  148. static int new_block = 1;
  149.  
  150. /* All the symbol-blocks (levels of scoping) in the compilation
  151.    are assigned sequence numbers in order of appearance of the
  152.    beginnings of the symbol-blocks.  Both final and dbxout do this,
  153.    and assume that they will both give the same number to each block.
  154.    Final uses these sequence numbers to generate assembler label names
  155.    LBBnnn and LBEnnn for the beginning and end of the symbol-block.
  156.    Dbxout uses the sequence nunbers to generate references to the same labels
  157.    from the dbx debugging information.
  158.  
  159.    Sdb records this level at the beginning
  160.    of each function, so that when it recurses down the declarations, it may
  161.    find the current level, since it outputs the block beginning and endings
  162.    at the point in the asm file, where the blocks would begin and end.  */
  163.  
  164. int next_block_index;
  165.  
  166. /* Chain of all `struct gdbfile's.  */
  167.  
  168. struct gdbfile *gdbfiles;
  169.  
  170. /* `struct gdbfile' for the last file we wrote a line number for.  */
  171.  
  172. static struct gdbfile *current_gdbfile;
  173.  
  174. /* Filenum to assign to the next distinct source file encountered.  */
  175.  
  176. static int next_gdb_filenum;
  177.  
  178. /* This variable contains machine-dependent flags (defined in tm-...h)
  179.    set and examined by output routines
  180.    that describe how to interpret the condition codes properly.  */
  181.  
  182. CC_STATUS cc_status;
  183.  
  184. /* During output of an insn, this contains a copy of cc_status
  185.    from before the insn.  */
  186.  
  187. CC_STATUS cc_prev_status;
  188.  
  189. /* Last source file name mentioned in a NOTE insn.  */
  190.  
  191. static char *lastfile;
  192.  
  193. /* Indexed by hardware reg number, is 1 if that register is ever
  194.    used in the current function.
  195.  
  196.    In life_analysis, or in stupid_life_analysis, this is set
  197.    up to record the hard regs used explicitly.  Reload adds
  198.    in the hard regs used for holding pseudo regs.  Final uses
  199.    it to generate the code in the function prologue and epilogue
  200.    to save and restore registers as needed.  */
  201.  
  202. char regs_ever_live[FIRST_PSEUDO_REGISTER];
  203.  
  204. /* Nonzero means current function must be given a frame pointer.
  205.    Set in stmt.c if anything is allocated on the stack there.
  206.    Set in reload1.c if anything is allocated on the stack there.  */
  207.  
  208. int frame_pointer_needed;
  209.  
  210. /* Assign unique numbers to labels generated for profiling.  */
  211.  
  212. int profile_label_no;
  213.  
  214. /* Length so far allocated in PENDING_BLOCKS.  */
  215.  
  216. static int max_block_depth;
  217.  
  218. /* Stack of sequence numbers of symbol-blocks of which we have seen the
  219.    beginning but not yet the end.  Sequence numbers are assigned at
  220.    the beginning; this stack allows us to find the sequence number
  221.    of a block that is ending.  */
  222.  
  223. static int *pending_blocks;
  224.  
  225. /* Number of elements currently in use in PENDING_BLOCKS.  */
  226.  
  227. static int block_depth;
  228.  
  229. /* Nonzero if have enabled APP processing of our assembler output.  */
  230.  
  231. static int app_on;
  232.  
  233. /* If we are outputting an insn sequence, this contains the sequence rtx.
  234.    Zero otherwise.  */
  235.  
  236. rtx final_sequence;
  237.  
  238. /* Initialize data in final at the beginning of a compilation.  */
  239.  
  240. void
  241. init_final (filename)
  242.      char *filename;
  243. {
  244.   next_block_index = 2;
  245.   lastfile = filename;
  246.   app_on = 0;
  247.   max_block_depth = 20;
  248.   pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
  249.   gdbfiles = 0;
  250.   next_gdb_filenum = 0;
  251.   final_sequence = 0;
  252. }
  253.  
  254. /* Called at end of source file,
  255.    to output the block-profiling table for this entire compilation.  */
  256.  
  257. void
  258. end_final (filename)
  259.      char *filename;
  260. {
  261.   int i;
  262.  
  263.   if (profile_block_flag)
  264.     {
  265.       char name[12];
  266.  
  267.       data_section ();
  268.  
  269.       /* Output the main header, of 6 words:
  270.      0:  1 if this file's initialized, else 0.
  271.      1:  address of file name.
  272.      2:  address of table of counts.
  273.      4:  number of counts in the table.
  274.      5:  always 0, for compatibility with Sun.
  275.      6:  extra word added by GNU: address of address table
  276.           which contains addresses of basic blocks,
  277.           in parallel with the table of counts.  */
  278.       ASM_OUTPUT_ALIGN (asm_out_file,
  279.             exact_log2 (min (UNITS_PER_WORD,
  280.                      BIGGEST_ALIGNMENT / BITS_PER_UNIT)));
  281.  
  282.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
  283.       assemble_integer_zero ();
  284.  
  285.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
  286.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  287.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
  288.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  289.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (CONST_INT, VOIDmode,
  290.                          count_basic_blocks));
  291.       assemble_integer_zero ();
  292.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
  293.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  294.  
  295.       /* Output the file name.  */
  296.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
  297.       assemble_string (filename, strlen (filename) + 1);
  298.  
  299.       /* Realign data section.  */
  300.       ASM_OUTPUT_ALIGN (asm_out_file,
  301.             exact_log2 (min (UNITS_PER_WORD,
  302.                      BIGGEST_ALIGNMENT / BITS_PER_UNIT)));
  303.  
  304.       /* Make space for the table of counts.  */
  305.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
  306.       ASM_OUTPUT_SKIP (asm_out_file, UNITS_PER_WORD * count_basic_blocks);
  307.  
  308.       /* Output the table of addresses.  */
  309.       text_section ();
  310.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
  311.       for (i = 0; i < count_basic_blocks; i++)
  312.     {
  313.       char name[12];
  314.       ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
  315.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  316.     }
  317.  
  318.       /* End with the address of the table of addresses,
  319.      so we can find it easily, as the last word in the file's text.  */
  320.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
  321.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  322.     }
  323. }
  324.  
  325. /* Enable APP processing of subsequent output.
  326.    Used before the output from an `asm' statement.  */
  327.  
  328. void
  329. app_enable ()
  330. {
  331.   if (! app_on)
  332.     {
  333.       fprintf (asm_out_file, ASM_APP_ON);
  334.       app_on = 1;
  335.     }
  336. }
  337.  
  338. /* Enable APP processing of subsequent output.
  339.    Called from varasm.c before most kinds of output.  */
  340.  
  341. void
  342. app_disable ()
  343. {
  344.   if (app_on)
  345.     {
  346.       fprintf (asm_out_file, ASM_APP_OFF);
  347.       app_on = 0;
  348.     }
  349. }
  350.  
  351. /* Return the number of slots filled in the current 
  352.    delayed branch sequence. */
  353.  
  354. #ifdef HAVE_DELAYED_BRANCH
  355. int
  356. dbr_sequence_length ()
  357. {
  358.   int i;
  359.   int slots = 0;
  360.   /* It's zero if we are not scheduling or not in a sequence. 
  361.      (We never count the first insn.)                  */
  362.   if (flag_delayed_branch && final_sequence != 0)
  363.     {
  364.       for (i = 1; i < XVECLEN (final_sequence, 0); i++)
  365.     slots += DBR_INSN_SLOTS (XVECEXP (final_sequence, 0, i));
  366.     }
  367.   return slots;
  368. }
  369. #endif
  370.  
  371. /* Output assembler code for the start of a function,
  372.    and initialize some of the variables in this file
  373.    for the new function.  The label for the function and associated
  374.    assembler pseudo-ops have already been output in `assemble_function'.
  375.  
  376.    FIRST is the first insn of the rtl for the function being compiled.
  377.    FILE is the file to write assembler code to.
  378.    WRITE_SYMBOLS says which kind of debugging info to write (or none).
  379.    OPTIMIZE is nonzero if we should eliminate redundant
  380.      test and compare insns.  */
  381.  
  382. void
  383. final_start_function (first, file, write_symbols, optimize)
  384.      rtx first;
  385.      FILE *file;
  386.      enum debugger write_symbols;
  387.      int optimize;
  388. {
  389.   block_depth = 0;
  390.  
  391.   this_is_asm_operands = 0;
  392.  
  393.   /* Record beginning of the symbol-block that's the entire function.  */
  394.  
  395.   if (write_symbols == GDB_DEBUG)
  396.     {
  397.       pending_blocks[block_depth++] = next_block_index;
  398.       fprintf (file, "\t.gdbbeg %d\n", next_block_index++);
  399.     }
  400.  
  401.   /* Initial line number is supposed to be output
  402.      before the function's prologue and label
  403.      so that the function's address will not appear to be
  404.      in the last statement of the preceding function.  */
  405.   if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
  406.     output_source_line (file, first, write_symbols);
  407.  
  408. #ifdef FUNCTION_PROLOGUE
  409.   /* First output the function prologue: code to set up the stack frame.  */
  410.   FUNCTION_PROLOGUE (file, get_frame_size ());
  411. #endif
  412.  
  413. #ifdef SDB_DEBUGGING_INFO
  414.   next_block_index = 1;
  415. #endif
  416.  
  417. #ifdef FUNCTION_BLOCK_PROFILER
  418.   if (profile_block_flag)
  419.     {
  420.       FUNCTION_BLOCK_PROFILER (file, profile_label_no);
  421.     }
  422. #endif /* FUNCTION_BLOCK_PROFILER */
  423.  
  424.   if (profile_flag)
  425.     {
  426.       int align = min (BIGGEST_ALIGNMENT, BITS_PER_WORD);
  427.       extern int current_function_returns_struct;
  428.       extern int current_function_needs_context;
  429.       int sval = current_function_returns_struct;
  430.       int cxt = current_function_needs_context;
  431.  
  432. #ifndef sprite      
  433.       data_section ();
  434.       ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
  435.       ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
  436.       assemble_integer_zero ();
  437.  
  438.       text_section ();
  439.  
  440. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  441.       if (sval)
  442.     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
  443. #else
  444. #ifdef STRUCT_VALUE_REGNUM
  445.       if (sval)
  446.     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
  447. #endif
  448. #endif
  449.  
  450. #if 0
  451. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  452.       if (cxt)
  453.     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
  454. #else
  455. #ifdef STATIC_CHAIN_REGNUM
  456.       if (cxt)
  457.     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
  458. #endif
  459. #endif
  460. #endif /* 0 */
  461. #endif
  462.  
  463.       FUNCTION_PROFILER (file, profile_label_no);
  464.  
  465. #if 0
  466. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  467.       if (cxt)
  468.     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
  469. #else
  470. #ifdef STATIC_CHAIN_REGNUM
  471.       if (cxt)
  472.     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
  473. #endif
  474. #endif
  475. #endif /* 0 */
  476.  
  477. #ifndef sprite      
  478. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  479.       if (sval)
  480.     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
  481. #else
  482. #ifdef STRUCT_VALUE_REGNUM
  483.       if (sval)
  484.     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
  485. #endif
  486. #endif
  487. #endif      
  488.     }
  489.  
  490.   profile_label_no++;
  491. }
  492.  
  493. /* Output assembler code for the end of a function.
  494.    For clarity, args are same as those of `final_start_function'
  495.    even though not all of them are needed.  */
  496.  
  497. void
  498. final_end_function (first, file, write_symbols, optimize)
  499.      rtx first;
  500.      FILE *file;
  501.      enum debugger write_symbols;
  502.      int optimize;
  503. {
  504.   if (app_on)
  505.     {
  506.       fprintf (file, ASM_APP_OFF);
  507.       app_on = 0;
  508.     }
  509.  
  510.   if (write_symbols == GDB_DEBUG)
  511.     fprintf (file, "\t.gdbend %d\n", pending_blocks[0]);
  512.  
  513. #ifdef SDB_DEBUGGING_INFO
  514.   if (write_symbols == SDB_DEBUG)
  515.     sdbout_end_function (last_linenum);
  516. #endif
  517.  
  518. #ifdef FUNCTION_EPILOGUE
  519.   /* Finally, output the function epilogue:
  520.      code to restore the stack frame and return to the caller.  */
  521.   FUNCTION_EPILOGUE (file, get_frame_size ());
  522. #endif
  523.  
  524. #ifdef SDB_DEBUGGING_INFO
  525.   if (write_symbols == SDB_DEBUG)
  526.     sdbout_end_epilogue ();
  527. #endif
  528.  
  529.   /* If FUNCTION_EPILOGUE is not defined, then the function body
  530.      itself contains return instructions wherever needed.  */
  531. }
  532.  
  533. /* Output assembler code for some insns: all or part of a function.
  534.    For description of args, see `final_start_function', above.
  535.  
  536.    PRESCAN is 1 if we are not really outputting,
  537.      just scanning as if we were outputting.
  538.    Prescanning deletes and rearranges insns just like ordinary output.
  539.    PRESCAN is -2 if we are outputting after having prescanned.
  540.    In this case, don't try to delete or rearrange insns
  541.    because that has already been done.
  542.    Prescanning is done only on certain machines.  */
  543.  
  544. void
  545. final (first, file, write_symbols, optimize, prescan)
  546.      rtx first;
  547.      FILE *file;
  548.      enum debugger write_symbols;
  549.      int optimize;
  550.      int prescan;
  551. {
  552.   register rtx insn;
  553.  
  554.   last_ignored_compare = 0;
  555.   new_block = 1;
  556.  
  557.   init_recog ();
  558.  
  559.   CC_STATUS_INIT;
  560.  
  561.   for (insn = NEXT_INSN (first); insn;)
  562.     insn = final_scan_insn (insn, file, write_symbols, optimize,
  563.                 prescan, 0);
  564. }
  565.  
  566. /* The final scan for one insn, INSN.
  567.    Args are same as in `final', except that INSN
  568.    is the insn being scanned.
  569.    Value returned is the next insn to be scanned.
  570.  
  571.    NOPEEPHOLES is the flag to disallow peephole processing (currently
  572.    used for within delayed branch sequence output).  */
  573.  
  574. rtx
  575. final_scan_insn  (insn, file, write_symbols, optimize, prescan, nopeepholes)
  576.      rtx insn;
  577.      FILE *file;
  578.      enum debugger write_symbols;
  579.      int optimize;
  580.      int prescan;
  581.      int nopeepholes;
  582. {
  583.   register int i;
  584.   switch (GET_CODE (insn))
  585.     {
  586.     case NOTE:
  587.       if (prescan > 0)
  588.     break;
  589.       if (write_symbols == NO_DEBUG)
  590.     break;
  591.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
  592.     {
  593. #ifdef SDB_DEBUGGING_INFO
  594.       if (write_symbols == SDB_DEBUG)
  595.         sdbout_begin_function (last_linenum);
  596. #endif
  597.       break;
  598.     }
  599.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
  600.       || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
  601.     break;
  602.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
  603.     break;            /* An insn that was "deleted" */
  604.       if (app_on)
  605.     {
  606.       fprintf (file, ASM_APP_OFF);
  607.       app_on = 0;
  608.     }
  609.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  610.     {
  611.       /* Beginning of a symbol-block.  Assign it a sequence number
  612.          and push the number onto the stack PENDING_BLOCKS.  */
  613.  
  614.       if (block_depth == max_block_depth)
  615.         {
  616.           /* PENDING_BLOCKS is full; make it longer.  */
  617.           max_block_depth *= 2;
  618.           pending_blocks
  619.         = (int *) xrealloc (pending_blocks,
  620.                     max_block_depth * sizeof (int));
  621.         }
  622.       pending_blocks[block_depth++] = next_block_index;
  623.  
  624.       /* Output debugging info about the symbol-block beginning.  */
  625.  
  626. #ifdef SDB_DEBUGGING_INFO
  627.       if (write_symbols == SDB_DEBUG)
  628.         sdbout_begin_block (file, last_linenum, next_block_index);
  629. #endif
  630. #ifdef DBX_DEBUGGING_INFO
  631.       if (write_symbols == DBX_DEBUG)
  632.         ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
  633. #endif
  634.       if (write_symbols == GDB_DEBUG)
  635.         fprintf (file, "\t.gdbbeg %d\n", next_block_index);
  636.  
  637.       next_block_index++;
  638.     }
  639.       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  640.     {
  641.       /* End of a symbol-block.  Pop its sequence number off
  642.          PENDING_BLOCKS and output debugging info based on that.  */
  643.  
  644.       --block_depth;
  645.  
  646. #ifdef DBX_DEBUGGING_INFO
  647.       if (write_symbols == DBX_DEBUG && block_depth >= 0)
  648.         ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
  649.                        pending_blocks[block_depth]);
  650. #endif
  651.  
  652. #ifdef SDB_DEBUGGING_INFO
  653.       if (write_symbols == SDB_DEBUG && block_depth >= 0)
  654.         sdbout_end_block (file, last_linenum);
  655. #endif
  656.  
  657.       if (write_symbols == GDB_DEBUG)
  658.         fprintf (file, "\t.gdbend %d\n", pending_blocks[block_depth]);
  659.     }
  660.       else if (NOTE_LINE_NUMBER (insn) > 0)
  661.     /* This note is a line-number.  */
  662.     output_source_line (file, insn, write_symbols);
  663.       break;
  664.  
  665.     case BARRIER:
  666. #ifdef ASM_OUTPUT_ALIGN_CODE
  667.       ASM_OUTPUT_ALIGN_CODE (file);
  668. #endif
  669.       break;
  670.  
  671.     case CODE_LABEL:
  672.       CC_STATUS_INIT;
  673.       if (prescan > 0)
  674.     break;
  675.       new_block = 1;
  676.       if (app_on)
  677.     {
  678.       fprintf (file, ASM_APP_OFF);
  679.       app_on = 0;
  680.     }
  681. #ifdef ASM_OUTPUT_CASE_LABEL
  682.       if (NEXT_INSN (insn) != 0
  683.       && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
  684.     {
  685.       rtx nextbody = PATTERN (NEXT_INSN (insn));
  686.  
  687.       /* If this label is followed by a jump-table,
  688.          output the two of them together in a special way.  */
  689.  
  690.       if (GET_CODE (nextbody) == ADDR_VEC
  691.           || GET_CODE (nextbody) == ADDR_DIFF_VEC)
  692.         {
  693.           ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
  694.                      NEXT_INSN (insn));
  695.           break;
  696.         }
  697.     }
  698. #endif
  699.  
  700.       ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
  701.       break;
  702.  
  703.     default:
  704.       {
  705.     register rtx body = PATTERN (insn);
  706.     int insn_code_number;
  707.     char *template;
  708.  
  709.     /* An INSN, JUMP_INSN or CALL_INSN.
  710.        First check for special kinds that recog doesn't recognize.  */
  711.  
  712.     if (GET_CODE (body) == USE /* These are just declarations */
  713.         || GET_CODE (body) == CLOBBER)
  714.       break;
  715.  
  716.     if (profile_block_flag && new_block)
  717.       {
  718.         new_block = 0;
  719.         /* Enable the table of basic-block use counts
  720.            to point at the code it applies to.  */
  721.         ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
  722.         /* Before first insn of this basic block, increment the
  723.            count of times it was entered.  */
  724. #ifdef BLOCK_PROFILER
  725.         BLOCK_PROFILER (file, count_basic_blocks);
  726. #endif
  727.         count_basic_blocks++;
  728.       }
  729.  
  730.     if (GET_CODE (body) == ASM_INPUT)
  731.       {
  732.         /* There's no telling what that did to the condition codes.  */
  733.         CC_STATUS_INIT;
  734.         if (prescan > 0)
  735.           break;
  736.         if (! app_on)
  737.           {
  738.         fprintf (file, ASM_APP_ON);
  739.         app_on = 1;
  740.           }
  741.         fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
  742.         break;
  743.       }
  744.  
  745.     /* Detect `asm' construct with operands.  */
  746.     if (asm_noperands (body) >= 0)
  747.       {
  748.         int noperands = asm_noperands (body);
  749.         rtx *ops;
  750.         char *string;
  751.  
  752.         /* There's no telling what that did to the condition codes.  */
  753.         CC_STATUS_INIT;
  754.         if (prescan > 0)
  755.           break;
  756.  
  757.         /* alloca won't do here, since only return from `final'
  758.            would free it.  */
  759.         if (noperands > 0)
  760.           ops = (rtx *) xmalloc (noperands * sizeof (rtx));
  761.  
  762.         if (! app_on)
  763.           {
  764.         fprintf (file, ASM_APP_ON);
  765.         app_on = 1;
  766.           }
  767.  
  768.         /* Get out the operand values.  */
  769.         string = decode_asm_operands (body, ops, 0, 0, 0);
  770.         /* Inhibit aborts on what would otherwise be compiler bugs.  */
  771.         insn_noperands = noperands;
  772.         this_is_asm_operands = insn;
  773.         /* Output the insn using them.  */
  774.         output_asm_insn (string, ops);
  775.         this_is_asm_operands = 0;
  776.         if (noperands > 0)
  777.           free (ops);
  778.         break;
  779.       }
  780.  
  781.     if (prescan <= 0 && app_on)
  782.       {
  783.         fprintf (file, ASM_APP_OFF);
  784.         app_on = 0;
  785.       }
  786.  
  787.     /* Detect insns that are really jump-tables
  788.        and output them as such.  */
  789.  
  790.     if (GET_CODE (body) == ADDR_VEC)
  791.       {
  792.         register int vlen, idx;
  793.  
  794.         if (prescan > 0)
  795.           break;
  796.  
  797.         vlen = XVECLEN (body, 0);
  798.         for (idx = 0; idx < vlen; idx++)
  799.           ASM_OUTPUT_ADDR_VEC_ELT (file,
  800.                        CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
  801. #ifdef ASM_OUTPUT_CASE_END
  802.         ASM_OUTPUT_CASE_END (file,
  803.                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
  804.                  insn);
  805. #endif
  806.         break;
  807.       }
  808.     if (GET_CODE (body) == ADDR_DIFF_VEC)
  809.       {
  810.         register int vlen, idx;
  811.  
  812.         if (prescan > 0)
  813.           break;
  814.  
  815.         vlen = XVECLEN (body, 1);
  816.         for (idx = 0; idx < vlen; idx++)
  817.           ASM_OUTPUT_ADDR_DIFF_ELT (file,
  818.                     CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
  819.                     CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
  820. #ifdef ASM_OUTPUT_CASE_END
  821.         ASM_OUTPUT_CASE_END (file,
  822.                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
  823.                  insn);
  824. #endif
  825.         break;
  826.       }
  827.  
  828.     if (recog_memoized (insn) == -1
  829.         && GET_CODE (body) == SEQUENCE) /* A delayed-branch sequence */
  830.       {
  831.         register int i;
  832.         if (prescan > 0)
  833.           break;
  834.         final_sequence = body;
  835.         for (i = 0; i < XVECLEN (body, 0); i++)
  836.           final_scan_insn (XVECEXP (body, 0, i), file, write_symbols,
  837.                    optimize, prescan, 1);
  838.         final_sequence = 0;
  839. #ifdef DBR_OUTPUT_SEQEND
  840.         DBR_OUTPUT_SEQEND (file);
  841. #endif
  842.         break;
  843.       }
  844.  
  845.     /* We have a real machine instruction as rtl.  */
  846.  
  847.     body = PATTERN (insn);
  848.  
  849.     /* Check for redundant test and compare instructions
  850.        (when the condition codes are already set up as desired).
  851.        This is done only when optimizing; if not optimizing,
  852.        it should be possible for the user to alter a variable
  853.        with the debugger in between statements
  854.        and the next statement should reexamine the variable
  855.        to compute the condition codes.  */
  856.  
  857.     if (optimize
  858.         && GET_CODE (body) == SET
  859.         && GET_CODE (SET_DEST (body)) == CC0
  860.         && insn != last_ignored_compare)
  861.       {
  862.         if (GET_CODE (SET_SRC (body)) == SUBREG)
  863.           SET_SRC (body) = alter_subreg (SET_SRC (body));
  864.         if ((cc_status.value1 != 0
  865.          && rtx_equal_p (SET_SRC (body), cc_status.value1))
  866.         || (cc_status.value2 != 0
  867.             && rtx_equal_p (SET_SRC (body), cc_status.value2)))
  868.           {
  869.         /* Don't delete insn if has an addressing side-effect */
  870.         if (! find_reg_note (insn, REG_INC, 0)
  871.             /* or if anything in it is volatile.  */
  872.             && ! volatile_refs_p (PATTERN (insn)))
  873.           {
  874.             /* We don't really delete the insn; just ignore it.  */
  875.             last_ignored_compare = insn;
  876.             break;
  877.           }
  878.           }
  879.       }
  880.  
  881.     /* Following a conditional branch, we have a new basic block.  */
  882.     if (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
  883.         && GET_CODE (SET_SRC (body)) != LABEL_REF)
  884.       new_block = 1;
  885.  
  886.     /* If this is a conditional branch, maybe modify it
  887.        if the cc's are in a nonstandard state
  888.        so that it accomplishes the same thing that it would
  889.        do straightforwardly if the cc's were set up normally.  */
  890.  
  891.     if (cc_status.flags != 0
  892.         && GET_CODE (insn) == JUMP_INSN
  893.         && GET_CODE (body) == SET
  894.         && SET_DEST (body) == pc_rtx
  895.         && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
  896.         /* This is done during prescan; it is not done again
  897.            in final scan when prescan has been done.  */
  898.         && prescan >= 0)
  899.       {
  900.         /* This function may alter the contents of its argument
  901.            and clear some of the cc_status.flags bits.
  902.            It may also return 1 meaning condition now always true
  903.            or -1 meaning condition now always false
  904.            or 2 meaning condition nontrivial but altered.  */
  905.         register int result = alter_cond (XEXP (SET_SRC (body), 0));
  906.         /* If condition now has fixed value, replace the IF_THEN_ELSE
  907.            with its then-operand or its else-operand.  */
  908.         if (result == 1)
  909.           SET_SRC (body) = XEXP (SET_SRC (body), 1);
  910.         if (result == -1)
  911.           SET_SRC (body) = XEXP (SET_SRC (body), 2);
  912.         /* The jump is now either unconditional or a no-op.
  913.            If it has become a no-op, don't try to output it.
  914.            (It would not be recognized.)  */
  915.         if (SET_SRC (body) == pc_rtx)
  916.           {
  917.         PUT_CODE (insn, NOTE);
  918.         NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  919.         NOTE_SOURCE_FILE (insn) = 0;
  920.         break;
  921.           }
  922.         /* Rerecognize the instruction if it has changed.  */
  923.         if (result != 0)
  924.           INSN_CODE (insn) = -1;
  925.       }
  926.  
  927. #ifdef STORE_FLAG_VALUE
  928.     /* Make same adjustments to instructions that examine the
  929.        condition codes without jumping (if this machine has them).  */
  930.  
  931.     if (cc_status.flags != 0
  932.         && GET_CODE (body) == SET)
  933.       switch (GET_CODE (SET_SRC (body)))
  934.         {
  935.         case GTU:
  936.         case GT:
  937.         case LTU:
  938.         case LT:
  939.         case GEU:
  940.         case GE:
  941.         case LEU:
  942.         case LE:
  943.         case EQ:
  944.         case NE:
  945.           {
  946.         register int result;
  947.         if (GET_CODE (XEXP (SET_SRC (body), 0)) != CC0)
  948.           break;
  949.         result = alter_cond (SET_SRC (body));
  950.         if (result == 1)
  951.           SET_SRC (body) = gen_rtx (CONST_INT, VOIDmode,
  952.                         STORE_FLAG_VALUE);
  953.         if (result == -1)
  954.           SET_SRC (body) = const0_rtx;
  955.         if (result != 0)
  956.           INSN_CODE (insn) = -1;
  957.           }
  958.         }
  959. #endif                /* STORE_FLAG_VALUE */
  960.  
  961.     /* Do machine-specific peephole optimizations if desired.  */
  962.  
  963.     if (optimize && !flag_no_peephole && !nopeepholes)
  964.       {
  965.         rtx next = peephole (insn);
  966.         /* When peepholing, if there were notes within the peephole,
  967.            emit them before the peephole.  */
  968.         if (next != 0 && next != NEXT_INSN (insn))
  969.           {
  970.         rtx note = NEXT_INSN (insn);
  971.         rtx prev = PREV_INSN (insn);
  972.         while (note != next)
  973.           {
  974.             final_scan_insn (note, file, write_symbols, optimize,
  975.                      prescan, nopeepholes);
  976.             note = NEXT_INSN (note);
  977.           }
  978.         /* In case this is prescan, put the notes
  979.            in proper position for later rescan.  */
  980.         note = NEXT_INSN (insn);
  981.         PREV_INSN (note) = prev;
  982.         NEXT_INSN (prev) = note;
  983.         NEXT_INSN (PREV_INSN (next)) = insn;
  984.         PREV_INSN (insn) = PREV_INSN (next);
  985.         NEXT_INSN (insn) = next;
  986.         PREV_INSN (next) = insn;
  987.           }
  988.  
  989.         /* PEEPHOLE might have changed this.  */
  990.         body = PATTERN (insn);
  991.       }
  992.  
  993.     /* Try to recognize the instruction.
  994.        If successful, verify that the operands satisfy the
  995.        constraints for the instruction.  Crash if they don't,
  996.        since `reload' should have changed them so that they do.  */
  997.  
  998.     insn_code_number = recog_memoized (insn);
  999.     insn_extract (insn);
  1000.     for (i = 0; i < insn_n_operands[insn_code_number]; i++)
  1001.       {
  1002.         if (GET_CODE (recog_operand[i]) == SUBREG)
  1003.           recog_operand[i] = alter_subreg (recog_operand[i]);
  1004.       }
  1005.  
  1006. #ifdef REGISTER_CONSTRAINTS
  1007.     if (! constrain_operands (insn_code_number))
  1008.       abort ();
  1009. #endif
  1010.  
  1011.     /* Some target machines need to prescan each insn before
  1012.        it is output.  */
  1013.  
  1014. #ifdef FINAL_PRESCAN_INSN
  1015.     FINAL_PRESCAN_INSN (insn, recog_operand,
  1016.                 insn_n_operands[insn_code_number]);
  1017. #endif
  1018.  
  1019.     cc_prev_status = cc_status;
  1020.  
  1021.     /* Update `cc_status' for this instruction.
  1022.        The instruction's output routine may change it further.
  1023.        If the output routine for a jump insn needs to depend
  1024.        on the cc status, it should look at cc_prev_status.  */
  1025.  
  1026.     NOTICE_UPDATE_CC (body, insn);
  1027.  
  1028.     /* If the proper template needs to be chosen by some C code,
  1029.        run that code and get the real template.  */
  1030.  
  1031.     template = insn_template[insn_code_number];
  1032.     if (template == 0)
  1033.       {
  1034.         template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
  1035.  
  1036.         /* If the C code returns 0, it means that it is a jump insn
  1037.            which follows a deleted test insn, and that test insn
  1038.            needs to be reinserted.  */
  1039.         if (template == 0)
  1040.           {
  1041.         if (PREV_INSN (insn) != last_ignored_compare)
  1042.           abort ();
  1043.         new_block = 0;
  1044.         return PREV_INSN (insn);
  1045.           }
  1046.       }
  1047.  
  1048.     if (prescan > 0)
  1049.       break;
  1050.  
  1051.     /* Output assembler code from the template.  */
  1052.  
  1053.     output_asm_insn (template, recog_operand);
  1054.  
  1055.     /* Mark this insn as having been output.  */
  1056.     INSN_DELETED_P (insn) = 1;
  1057.       }
  1058.     }
  1059.   return NEXT_INSN (insn);
  1060. }
  1061.  
  1062. /* Set up FILENAME as the current file for GDB line-number output.  */
  1063.  
  1064. void
  1065. set_current_gdbfile (filename)
  1066.      char *filename;
  1067. {
  1068.   register struct gdbfile *f;
  1069.   for (f = gdbfiles; f; f = f->next)
  1070.     if (!strcmp (f->name, filename))
  1071.       break;
  1072.  
  1073.   if (!f)
  1074.     {
  1075.       f = (struct gdbfile *) permalloc (sizeof (struct gdbfile));
  1076.       f->next = gdbfiles;
  1077.       gdbfiles = f;
  1078.       f->name = filename;
  1079.       f->filenum = next_gdb_filenum++;
  1080.       f->nlines = 0;
  1081.     }
  1082.   current_gdbfile = f;
  1083.   lastfile = filename;
  1084. }
  1085.  
  1086. /* Output debugging info to the assembler file FILE
  1087.    based on the NOTE-insn INSN, assumed to be a line number.  */
  1088.  
  1089. static void
  1090. output_source_line (file, insn, write_symbols)
  1091.      FILE *file;
  1092.      rtx insn;
  1093.      enum debugger write_symbols;
  1094. {
  1095.   register char *filename = NOTE_SOURCE_FILE (insn);
  1096.  
  1097.   last_linenum = NOTE_LINE_NUMBER (insn);
  1098.  
  1099.   if (write_symbols == GDB_DEBUG)
  1100.     {
  1101.       /* Output GDB-format line number info.  */
  1102.  
  1103.       /* If this is not the same source file as last time,
  1104.      find or assign a GDB-file-number to this file.  */
  1105.       if (filename && (lastfile == 0 || strcmp (filename, lastfile)
  1106.                || current_gdbfile == 0))
  1107.     set_current_gdbfile (filename);
  1108.  
  1109.       ++current_gdbfile->nlines;
  1110.       fprintf (file, "\t.gdbline %d,%d\n",
  1111.            current_gdbfile->filenum, NOTE_LINE_NUMBER (insn));
  1112.     }
  1113.  
  1114.   if (write_symbols == SDB_DEBUG || write_symbols == DBX_DEBUG)
  1115.     {
  1116. #ifdef SDB_DEBUGGING_INFO
  1117.       if (write_symbols == SDB_DEBUG
  1118. #if 0 /* People like having line numbers even in wrong file!  */
  1119.       /* COFF can't handle multiple source files--lose, lose.  */
  1120.       && !strcmp (filename, main_input_filename)
  1121. #endif
  1122.       /* COFF relative line numbers must be positive.  */
  1123.       && last_linenum > sdb_begin_function_line)
  1124.     {
  1125. #ifdef ASM_OUTPUT_SOURCE_LINE
  1126.       ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
  1127. #else
  1128.       fprintf (file, "\t.ln\t%d\n",
  1129.            (sdb_begin_function_line
  1130.             ? last_linenum - sdb_begin_function_line : 1));
  1131. #endif
  1132.     }
  1133. #endif
  1134.  
  1135. #ifdef DBX_DEBUGGING_INFO
  1136.       if (write_symbols == DBX_DEBUG)
  1137.     {
  1138.       /* Write DBX line number data.  */
  1139.  
  1140.       if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
  1141.         {
  1142. #ifdef ASM_OUTPUT_SOURCE_FILENAME
  1143.           ASM_OUTPUT_SOURCE_FILENAME (file, filename);
  1144. #else
  1145.           fprintf (file, "\t.stabs \"%s\",%d,0,0,Ltext\n",
  1146.                filename, N_SOL);
  1147. #endif
  1148.           lastfile = filename;
  1149.         }
  1150.     }
  1151.  
  1152. #ifdef ASM_OUTPUT_SOURCE_LINE
  1153.       ASM_OUTPUT_SOURCE_LINE (file, NOTE_LINE_NUMBER (insn));
  1154. #else
  1155.       fprintf (file, "\t.stabd %d,0,%d\n",
  1156.            N_SLINE, NOTE_LINE_NUMBER (insn));
  1157. #endif
  1158. #endif /* DBX_DEBUGGING_INFO */
  1159.     }
  1160. }
  1161.  
  1162. /* If X is a SUBREG, replace it with a REG or a MEM,
  1163.    based on the thing it is a subreg of.  */
  1164.  
  1165. rtx
  1166. alter_subreg (x)
  1167.      register rtx x;
  1168. {
  1169.   register rtx y = SUBREG_REG (x);
  1170.   if (GET_CODE (y) == SUBREG)
  1171.     y = alter_subreg (y);
  1172.  
  1173.   if (GET_CODE (y) == REG)
  1174.     {
  1175.       /* If the containing reg really gets a hard reg, so do we.  */
  1176.       PUT_CODE (x, REG);
  1177.       REGNO (x) = REGNO (y) + SUBREG_WORD (x);
  1178.     }
  1179.   else if (GET_CODE (y) == MEM)
  1180.     {
  1181.       register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  1182. #ifdef BYTES_BIG_ENDIAN
  1183.       offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
  1184.          - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
  1185. #endif
  1186.       PUT_CODE (x, MEM);
  1187.       MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
  1188.       XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
  1189.     }
  1190.   else if (GET_CODE (y) == CONST_DOUBLE)
  1191.     return y;
  1192.  
  1193.   return x;
  1194. }
  1195.  
  1196. /* Do alter_subreg on all the SUBREGs contained in X.  */
  1197.  
  1198. static rtx
  1199. walk_alter_subreg (x)
  1200.      rtx x;
  1201. {
  1202.   switch (GET_CODE (x))
  1203.     {
  1204.     case PLUS:
  1205.     case MULT:
  1206.       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
  1207.       XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
  1208.       break;
  1209.  
  1210.     case MEM:
  1211.       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
  1212.       break;
  1213.  
  1214.     case SUBREG:
  1215.       return alter_subreg (x);
  1216.     }
  1217.  
  1218.   return x;
  1219. }
  1220.  
  1221. /* Given BODY, the body of a jump instruction, alter the jump condition
  1222.    as required by the bits that are set in cc_status.flags.
  1223.    Not all of the bits there can be handled at this level in all cases.
  1224.  
  1225.    The value is normally 0.
  1226.    1 means that the condition has become always true.
  1227.    -1 means that the condition has become always false.
  1228.    2 means that COND has been altered.  */
  1229.  
  1230. static int
  1231. alter_cond (cond)
  1232.      register rtx cond;
  1233. {
  1234.   int value = 0;
  1235.  
  1236.   if (cc_status.flags & CC_REVERSED)
  1237.     {
  1238.       value = 2;
  1239.       switch (GET_CODE (cond))
  1240.     {
  1241.     case LE:
  1242.       PUT_CODE (cond, GE);
  1243.       break;
  1244.     case GE:
  1245.       PUT_CODE (cond, LE);
  1246.       break;
  1247.     case LT:
  1248.       PUT_CODE (cond, GT);
  1249.       break;
  1250.     case GT:
  1251.       PUT_CODE (cond, LT);
  1252.       break;
  1253.     case LEU:
  1254.       PUT_CODE (cond, GEU);
  1255.       break;
  1256.     case GEU:
  1257.       PUT_CODE (cond, LEU);
  1258.       break;
  1259.     case LTU:
  1260.       PUT_CODE (cond, GTU);
  1261.       break;
  1262.     case GTU:
  1263.       PUT_CODE (cond, LTU);
  1264.       break;
  1265.     }
  1266.     }
  1267.  
  1268.   if (cc_status.flags & CC_NOT_POSITIVE)
  1269.     switch (GET_CODE (cond))
  1270.       {
  1271.       case LE:
  1272.       case LEU:
  1273.       case GEU:
  1274.     /* Jump becomes unconditional.  */
  1275.     return 1;
  1276.  
  1277.       case GT:
  1278.       case GTU:
  1279.       case LTU:
  1280.     /* Jump becomes no-op.  */
  1281.     return -1;
  1282.  
  1283.       case GE:
  1284.     PUT_CODE (cond, EQ);
  1285.     value = 2;
  1286.     break;
  1287.  
  1288.       case LT:
  1289.     PUT_CODE (cond, NE);
  1290.     value = 2;
  1291.     break;
  1292.       }
  1293.  
  1294.   if (cc_status.flags & CC_NOT_NEGATIVE)
  1295.     switch (GET_CODE (cond))
  1296.       {
  1297.       case GE:
  1298.       case GEU:
  1299.     /* Jump becomes unconditional.  */
  1300.     return 1;
  1301.  
  1302.       case LT:
  1303.       case LTU:
  1304.     /* Jump becomes no-op.  */
  1305.     return -1;
  1306.  
  1307.       case LE:
  1308.       case LEU:
  1309.     PUT_CODE (cond, EQ);
  1310.     value = 2;
  1311.     break;
  1312.  
  1313.       case GT:
  1314.       case GTU:
  1315.     PUT_CODE (cond, NE);
  1316.     value = 2;
  1317.     break;
  1318.       }
  1319.  
  1320.   if (cc_status.flags & CC_NO_OVERFLOW)
  1321.     switch (GET_CODE (cond))
  1322.       {
  1323.       case GEU:
  1324.     /* Jump becomes unconditional.  */
  1325.     return 1;
  1326.  
  1327.       case LEU:
  1328.     PUT_CODE (cond, EQ);
  1329.     value = 2;
  1330.     break;
  1331.  
  1332.       case GTU:
  1333.     PUT_CODE (cond, NE);
  1334.     value = 2;
  1335.     break;
  1336.  
  1337.       case LTU:
  1338.     /* Jump becomes no-op.  */
  1339.     return -1;
  1340.       }
  1341.  
  1342.   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
  1343.     switch (GET_CODE (cond))
  1344.       {
  1345.       case LE:
  1346.       case LEU:
  1347.       case GE:
  1348.       case GEU:
  1349.       case LT:
  1350.       case LTU:
  1351.       case GT:
  1352.       case GTU:
  1353.     abort ();
  1354.  
  1355.       case NE:
  1356.     PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
  1357.     value = 2;
  1358.     break;
  1359.  
  1360.       case EQ:
  1361.     PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
  1362.     value = 2;
  1363.     break;
  1364.       }
  1365.   
  1366.   return value;
  1367. }
  1368.  
  1369. /* Report inconsistency between the assembler template and the operands.
  1370.    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
  1371.  
  1372. static void
  1373. output_operand_lossage (str)
  1374.      char *str;
  1375. {
  1376.   if (this_is_asm_operands)
  1377.     error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
  1378.   else
  1379.     abort ();
  1380. }
  1381.  
  1382. /* Output of assembler code from a template, and its subroutines.  */
  1383.  
  1384. /* Output text from TEMPLATE to the assembler output file,
  1385.    obeying %-directions to substitute operands taken from
  1386.    the vector OPERANDS.
  1387.  
  1388.    %N (for N a digit) means print operand N in usual manner.
  1389.    %lN means require operand N to be a CODE_LABEL or LABEL_REF
  1390.       and print the label name with no punctuation.
  1391.    %cN means require operand N to be a constant
  1392.       and print the constant expression with no punctuation.
  1393.    %aN means expect operand N to be a memory address
  1394.       (not a memory reference!) and print a reference
  1395.       to that address.
  1396.    %nN means expect operand N to be a constant
  1397.       and print a constant expression for minus the value
  1398.       of the operand, with no other punctuation.  */
  1399.  
  1400. void
  1401. output_asm_insn (template, operands)
  1402.      char *template;
  1403.      rtx *operands;
  1404. {
  1405.   register char *p;
  1406.   register int c;
  1407.  
  1408.   /* An insn may return a null string template
  1409.      in a case where no assembler code is needed.  */
  1410.   if (*template == 0)
  1411.     return;
  1412.  
  1413.   p = template;
  1414.   putc ('\t', asm_out_file);
  1415.  
  1416. #ifdef ASM_OUTPUT_OPCODE
  1417.   ASM_OUTPUT_OPCODE (asm_out_file, p);
  1418. #endif
  1419.  
  1420.   while (c = *p++)
  1421.     {
  1422. #ifdef ASM_OUTPUT_OPCODE
  1423.       if (c == '\n')
  1424.     {
  1425.       putc (c, asm_out_file);
  1426.       while ((c = *p) == '\t')
  1427.         {
  1428.           putc (c, asm_out_file);
  1429.           p++;
  1430.         }
  1431.       ASM_OUTPUT_OPCODE (asm_out_file, p);
  1432.     }
  1433.       else
  1434. #endif
  1435.       if (c != '%')
  1436.     putc (c, asm_out_file);
  1437.       else
  1438.     {
  1439.       /* %% outputs a single %.  */
  1440.       if (*p == '%')
  1441.         {
  1442.           p++;
  1443.           putc (c, asm_out_file);
  1444.         }
  1445.       /* % followed by a letter and some digits
  1446.          outputs an operand in a special way depending on the letter.
  1447.          Letters `acln' are implemented here.
  1448.          Other letters are passed to `output_operand' so that
  1449.          the PRINT_OPERAND macro can define them.  */
  1450.       else if ((*p >= 'a' && *p <= 'z')
  1451.            || (*p >= 'A' && *p <= 'Z'))
  1452.         {
  1453.           int letter = *p++;
  1454.           c = atoi (p);
  1455.  
  1456.           if (! (*p >= '0' && *p <= '9'))
  1457.         output_operand_lossage ("operand number missing after %-letter");
  1458.           else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
  1459.         output_operand_lossage ("operand number out of range");
  1460.           else if (letter == 'l')
  1461.         output_asm_label (operands[c]);
  1462.           else if (letter == 'a')
  1463.         output_address (operands[c]);
  1464.           else if (letter == 'c')
  1465.         {
  1466.           if (CONSTANT_ADDRESS_P (operands[c]))
  1467.             output_addr_const (asm_out_file, operands[c]);
  1468.           else
  1469.             output_operand (operands[c], 'c');
  1470.         }
  1471.           else if (letter == 'n')
  1472.         {
  1473.           if (GET_CODE (operands[c]) == CONST_INT)
  1474.             fprintf (asm_out_file, "%d", - INTVAL (operands[c]));
  1475.           else
  1476.             {
  1477.               putc ('-', asm_out_file);
  1478.               output_addr_const (asm_out_file, operands[c]);
  1479.             }
  1480.         }
  1481.           else
  1482.         output_operand (operands[c], letter);
  1483.  
  1484.           while ((c = *p) >= '0' && c <= '9') p++;
  1485.         }
  1486.       /* % followed by a digit outputs an operand the default way.  */
  1487.       else if (*p >= '0' && *p <= '9')
  1488.         {
  1489.           c = atoi (p);
  1490.           if (this_is_asm_operands && c >= (unsigned) insn_noperands)
  1491.         output_operand_lossage ("operand number out of range");
  1492.           else
  1493.         output_operand (operands[c], 0);
  1494.           while ((c = *p) >= '0' && c <= '9') p++;
  1495.         }
  1496.       /* % followed by punctuation: output something for that
  1497.          punctuation character alone, with no operand.
  1498.          The PRINT_OPERAND macro decides what is actually done.  */
  1499. #ifdef PRINT_OPERAND_PUNCT_VALID_P
  1500.       else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
  1501.         output_operand (0, *p++);
  1502. #endif
  1503.       else
  1504.         output_operand_lossage ("invalid %%-code");
  1505.     }
  1506.     }
  1507.  
  1508.   putc ('\n', asm_out_file);
  1509. }
  1510.  
  1511. /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
  1512.  
  1513. void
  1514. output_asm_label (x)
  1515.      rtx x;
  1516. {
  1517.   char buf[256];
  1518.  
  1519.   if (GET_CODE (x) == LABEL_REF)
  1520.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
  1521.   else if (GET_CODE (x) == CODE_LABEL)
  1522.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  1523.   else
  1524.     output_operand_lossage ("`%l' operand isn't a label");
  1525.  
  1526.   assemble_name (asm_out_file, buf);
  1527. }
  1528.  
  1529. /* Print operand X using machine-dependent assembler syntax.
  1530.    The macro PRINT_OPERAND is defined just to control this function.
  1531.    CODE is a non-digit that preceded the operand-number in the % spec,
  1532.    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
  1533.    between the % and the digits.
  1534.    When CODE is a non-letter, X is 0.
  1535.  
  1536.    The meanings of the letters are machine-dependent and controlled
  1537.    by PRINT_OPERAND.  */
  1538.  
  1539. static void
  1540. output_operand (x, code)
  1541.      rtx x;
  1542.      int code;
  1543. {
  1544.   if (x && GET_CODE (x) == SUBREG)
  1545.     x = alter_subreg (x);
  1546.   PRINT_OPERAND (asm_out_file, x, code);
  1547. }
  1548.  
  1549. /* Print a memory reference operand for address X
  1550.    using machine-dependent assembler syntax.
  1551.    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
  1552.  
  1553. void
  1554. output_address (x)
  1555.      rtx x;
  1556. {
  1557.   walk_alter_subreg (x);
  1558.   PRINT_OPERAND_ADDRESS (asm_out_file, x);
  1559. }
  1560.  
  1561. /* Print an integer constant expression in assembler syntax.
  1562.    Addition and subtraction are the only arithmetic
  1563.    that may appear in these expressions.  */
  1564.  
  1565. void
  1566. output_addr_const (file, x)
  1567.      FILE *file;
  1568.      rtx x;
  1569. {
  1570.   char buf[256];
  1571.  
  1572.  restart:
  1573.   switch (GET_CODE (x))
  1574.     {
  1575.     case SYMBOL_REF:
  1576.       assemble_name (file, XSTR (x, 0));
  1577.       break;
  1578.  
  1579.     case LABEL_REF:
  1580.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
  1581.       assemble_name (asm_out_file, buf);
  1582.       break;
  1583.  
  1584.     case CODE_LABEL:
  1585.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  1586.       assemble_name (asm_out_file, buf);
  1587.       break;
  1588.  
  1589.     case CONST_INT:
  1590.       fprintf (file, "%d", INTVAL (x));
  1591.       break;
  1592.  
  1593.     case CONST:
  1594.       x = XEXP (x, 0);
  1595.       goto restart;
  1596.  
  1597.     case CONST_DOUBLE:
  1598.       if (GET_MODE (x) == DImode)
  1599.     {
  1600.       /* We can use %d if the number is <32 bits and positive.  */
  1601.       if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
  1602.         fprintf (file, "0x%x%08x",
  1603.              CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
  1604.       else
  1605.         fprintf (file, "%d", CONST_DOUBLE_LOW (x));
  1606.     }
  1607.       else
  1608.     /* We can't handle floating point constants;
  1609.        PRINT_OPERAND must handle them.  */
  1610.     output_operand_lossage ("floating constant misused");
  1611.       break;
  1612.  
  1613.     case PLUS:
  1614.       /* Some assemblers need integer constants to appear last (eg masm).  */
  1615.       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
  1616.     {
  1617.       output_addr_const (file, XEXP (x, 1));
  1618.       if (INTVAL (XEXP (x, 0)) >= 0)
  1619.         fprintf (file, "+");
  1620.       output_addr_const (file, XEXP (x, 0));
  1621.     }
  1622.       else
  1623.     {
  1624.       output_addr_const (file, XEXP (x, 0));
  1625.       if (INTVAL (XEXP (x, 1)) >= 0)
  1626.         fprintf (file, "+");
  1627.       output_addr_const (file, XEXP (x, 1));
  1628.     }
  1629.       break;
  1630.  
  1631.     case MINUS:
  1632.       output_addr_const (file, XEXP (x, 0));
  1633.       fprintf (file, "-");
  1634.       output_addr_const (file, XEXP (x, 1));
  1635.       break;
  1636.  
  1637.     default:
  1638.       output_operand_lossage ("invalid expression as operand");
  1639.     }
  1640. }
  1641. @
  1642.  
  1643.  
  1644. 1.1
  1645. log
  1646. @Initial revision
  1647. @
  1648. text
  1649. @d404 1
  1650. d433 1
  1651. d449 1
  1652. d459 1
  1653. @
  1654.